
/*
vgInspector.cc
This file is part of opengl-vrml-assembly.
Copyright (C) Rafal Pielech, rafal.pielech@gmail.com

opengl-vrml-assembly is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

opengl-vrml-assembly is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with opengl-vrml-assembly.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <windows.h>
#include <vgDebug.h>
#include <vgInspector.h>

vgInspector::vgInspector(void) : inspConStdOutHd(INVALID_HANDLE_VALUE),
                                 inspNotificationMsgId(0)
{
  VG_DEBUG
}

int vgInspector::vgRun(void)
{
  if(::AllocConsole())
  {
    inspConStdOutHd = ::GetStdHandle(STD_OUTPUT_HANDLE);
    if(inspConStdOutHd)
    {
      inspNotificationMsgId = ::RegisterWindowMessage(VG_INSPECTOR_NOTIFICATION);
      if((inspNotificationMsgId >= 0xC000) && (inspNotificationMsgId <= 0xFFFF))
      {
        MSG msg;
        ::PostMessage(HWND_BROADCAST, inspNotificationMsgId, 0, 0);
        while(::GetMessage(&msg, NULL, 0, 0) > 0)
        {
          break;
        }
      }
      ::CloseHandle(inspConStdOutHd);
    }
    ::FreeConsole();
  }
  return 0;
}

vgInspector::~vgInspector(void)
{
  VG_DEBUG
}

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpCmdLine,
                     int nCmdShow)
{
  VG_DEBUG
  vgInspector inspector;
  return inspector.vgRun();
}
